package com.sgb.kjwl.view.ui.activity.transport;

import android.content.Context;
import android.content.Intent;
import android.view.View;

import androidx.fragment.app.Fragment;
import androidx.lifecycle.ViewModelProvider;

import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ActivityProfessionalServiceBinding;
import com.sgb.kjwl.view.ui.fragment.transport.ProfessionalServicesFragment;
import com.sgb.kjwl.viewmodel.transport.ProfessionalServiceModel;
import com.swgk.core.common.base.BaseActivity;
import com.swgk.core.common.base.BaseViewModel;
import com.swgk.core.recyclerview.adapter.FragPagerAdapter;

import java.util.ArrayList;

public class ProfessionalServicesActivity extends BaseActivity<BaseViewModel, ActivityProfessionalServiceBinding> {

    private String[] titles = {"维修服务", "轮胎配件", "加油服务", "保险服务", "代办服务", "开票服务"};
    private FragPagerAdapter pagerAdapter;
    private ArrayList<Fragment> mFragments;
    public int index = 0;

    public static void start(Context context) {
        Intent intent = new Intent(context, ProfessionalServicesActivity.class);
        intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
        context.startActivity(intent);
    }

    @Override
    protected int layoutId() {
        return R.layout.activity_professional_service;
    }

    @Override
    protected void createViewModel() {
        mViewModel = new ViewModelProvider(this).get(ProfessionalServiceModel.class);
    }

    @Override
    protected void init() {
        mBinding.ivBack.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });

        mFragments = new ArrayList<>();
        for (int i = 0; i < titles.length; i++) {
            mFragments.add(ProfessionalServicesFragment.newInstance());
        }

        pagerAdapter = new FragPagerAdapter(getSupportFragmentManager(), mFragments);
        mBinding.viewpager.setAdapter(pagerAdapter);
        mBinding.viewpager.setOffscreenPageLimit(3);
        mBinding.tabLayout.setViewPager(mBinding.viewpager, titles);
        mBinding.viewpager.setCurrentItem(index);
    }
}
